package com.itkaien.javaeebased.demo042;

import java.util.*;

public class PokerGame1 {

    static Map<Integer, String> pokerMap = new HashMap<>();

    static List<Integer> pokerList = new ArrayList<>();

    static {
        System.out.println("加载牌库资源");
        String[] color = {"♠", "♥", "♣", "♦"};
        String[] number = {"A", "2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K"};

        int seialNumber=1;
        for (String numberOne:number) {
            for (String colorOne:color){
                pokerMap.put(seialNumber, colorOne+numberOne);
                pokerList.add(seialNumber);
                seialNumber++;
            }
        }
        pokerMap.put(seialNumber, "大王");
        pokerList.add(seialNumber);
        seialNumber++;
        pokerList.add(seialNumber);
        pokerMap.put(seialNumber, "小王");
    }

    public PokerGame1() {
        //准备牌
        System.out.println(pokerMap);
        System.out.println(pokerList);
        //洗牌
        Collections.shuffle(pokerList);

        //发牌
        TreeSet lineCard = new TreeSet<>();

        TreeSet player1 = new TreeSet<>();
        TreeSet player2 = new TreeSet<>();
        TreeSet player3 = new TreeSet<>();


        for (int i = 0; i < pokerList.size(); i++) {
            Integer orderNumber = pokerList.get(i);
            if (i < 3) {
                lineCard.add(orderNumber);
                continue;
            }
            if (i % 3 == 0) {
                player1.add(orderNumber);
            } else if (i % 3 == 1) {
                player2.add(orderNumber);
            } else if (i % 3 == 2) {
                player3.add(orderNumber);
            }
        }
//        看牌
        lookPoker("地牌", lineCard);
        lookPoker("玩家1", player1);
        lookPoker("玩家2", player2);
        lookPoker("玩家3", player3);
    }

    public void lookPoker(String name, Set<Integer> set) {
        System.out.print(name + "的牌是:");
        for (Integer poker : set) {
            System.out.print(pokerMap.get(poker) + " ");
        }
        System.out.println();
    }
}
